package com.yunhe.util;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class DruidTest {
    static ClassPathXmlApplicationContext cpac = null;

    static {
        cpac = new ClassPathXmlApplicationContext("applicationContext.xml");
    }
    @Test
    public  void druid() throws Exception {
        DruidDataSource dds=new DruidDataSource();
        dds.setDriverClassName("com.mysql.jdbc.Driver");
        dds.setUrl("jdbc:mysql://localhost:3306/mybatis");
        dds.setUsername("root");
        dds.setPassword("admin");
        DruidPooledConnection connection = dds.getConnection();
        System.out.println(connection);
    }
    @Test
    public void spring_druid() throws Exception {
        DataSource ds= (DataSource) cpac.getBean("druid");
        Connection connection = ds.getConnection();
        System.out.println(connection);
    }

    @Test
    public void datesource2() throws Exception {
        DataSource ds= (DataSource) cpac.getBean("dateSource2");
        Connection connection = ds.getConnection();
        System.out.println(connection);
    }

}
